<?php
require_once('../libraryfiles/config.php');
$content = 'create_f_social.php';
$include='
<script src="'.W_ROOT.'/js/jquery.js" type="text/javascript"></script>
';
require_once TMP_USER_PATH;

$error = isset($_GET['error'])?$_GET['error']:'';
$var = '';
?>

<script type="text/javascript">
function display(obj,id,id1) {
var txt = obj.value;
document.getElementById(id).style.display = 'none';
document.getElementById(id1).style.display = 'block';
if (txt!=0) {
document.getElementById(id).style.display = 'block';
document.getElementById(id1).style.display = 'none';
}
}
</script>


<!--social-->
<?php
if(!empty($_GET["provider"])){
	// config and whatnot
    $config = dirname(__FILE__) . '/../hybridauth/config.php';
    require_once( "../hybridauth/Hybrid/Auth.php" );
	$user_data = NULL;

	// try to get the user profile from an authenticated provider
	try{
		$hybridauth = new Hybrid_Auth($config);
		$connected_adapters_list = $hybridauth->getConnectedProviders(); 

		// selected provider name 
		$provider = @ trim( strip_tags( $_GET["provider"] ) );

		// check if the user is currently connected to the selected provider
		if( !  $hybridauth->isConnectedWith( $provider ) ){ 
			// redirect him back to login page
			header( "Location: login.php?error=Your are not connected to $provider or your session has expired" );
		}

		// call back the requested provider adapter instance (no need to use authenticate() as we already did on login page)
		$adapter = $hybridauth->getAdapter( $provider );

		// grab the user profile
		$user_data = $adapter->getUserProfile();
    }
	catch( Exception $e ){  
		// In case we have errors 6 or 7, then we have to use Hybrid_Provider_Adapter::logout() to 
		// let hybridauth forget all about the user so we can try to authenticate again.

		// Display the recived error, 
		// to know more please refer to Exceptions handling section on the userguide
		switch( $e->getCode() ){ 
			case 0 : echo "Unspecified error."; break;
			case 1 : echo "Hybriauth configuration error."; break;
			case 2 : echo "Provider not properly configured."; break;
			case 3 : echo "Unknown or disabled provider."; break;
			case 4 : echo "Missing provider application credentials."; break;
			case 5 : echo "Authentification failed. " 
					  . "The user has canceled the authentication or the provider refused the connection."; 
			case 6 : echo "User profile request failed. Most likely the user is not connected "
					  . "to the provider and he should to authenticate again."; 
				   $adapter->logout(); 
				   break;
			case 7 : echo "User not connected to the provider."; 
				   $adapter->logout(); 
				   break;
		} 

		echo "<br /><br /><b>Original error message:</b> " . $e->getMessage();

		echo "<hr /><h3>Trace</h3> <pre>" . $e->getTraceAsString() . "</pre>";  
	}
			$provider_uid  = $user_data->identifier;
			$email         = $user_data->email;
			$first_name    = $user_data->firstName;
			$last_name     = $user_data->lastName;
			$username = $first_name;
			$username = strtolower($username);
			$display_name  = $user_data->displayName;
			$website_url   = $user_data->webSiteURL;
			$profile_url   = $user_data->profileURL;			
			$photo_url   = $user_data->photoURL;
			$gender   = $user_data->gender;
			$age   = $user_data->age;
			$birth_day   = $user_data->birthDay;
			$birth_month   = $user_data->birthMonth;
			$birth_year   = $user_data->birthYear;
			$phone   = $user_data->phone;
			$address   = $user_data->address;
			$country   = $user_data->country;
			$region   = $user_data->region;
			$city   = $user_data->city;
			$zip   = $user_data->zip;
			$password      = rand( ) ;
}
 else
 {
 			$provider_uid  = '';
			$email         = '';
			$first_name    = '';
			$last_name     = '';
			$display_name  = '';
			$website_url   = '';
			$profile_url   = '';			
			$photo_url   = '';
			$gender   = '';
			$age   = '';
			$birth_day   = '';
			$birth_month   = '';
			$birth_year   = '';
			$phone   = '';
			$address   = '';
			$country   = '';
			$region   = '';
			$city   = '';
			$zip   = '';
			$password = '';
}
require_once('check.php');
?>
<!--end social-->
<div class="row">
	<div class="box">
        <div class="title">Select Your Account!</div>
        <div class="center">
        <p align="center"><strong>Select Your Account Type</strong></p>
        <?php
        if($error!="")
        {
        ?>
        <div align="center"><strong style="color:#F00;"><?php echo $error;?></strong></div>
        <?php
        }
        ?>
            <div class="row">
            	<div class="six columns">
                    <label class="checkbox" class="span6">
                    <input type="radio" name="accounttype" value="3" onClick="display(this,3,2);">&nbsp;Buyer&nbsp;&nbsp;&nbsp;
                    </label>
                </div>
                <div class="six columns">
                    <label class="checkbox">
                        <input type="radio" name="accounttype" value="2" onClick="display(this,2,3);">&nbsp;Seller
                    </label>
                </div>
            </div>
        </div>
        <br />
        <div id="3" style="display: none;">
        <div class="title">
        Register as a Buyer
        </div>
        <div class="center">
        <?php include_once('buyer_register.php')?>
        </div>
        </div>
        <div id="2" style="display: none;">
        <div class="title">
        Register as a Seller
        </div>
        <div class="center">
        <?php include_once('seller_register.php')?>
        </div>
        </div>
        <div style="clear:both;"></div>
	</div>
</div>